package com.atguigu.spzx.cart.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.h5.CartItem;
import com.atguigu.spzx.cart.service.CartService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2023-11-20-21:02
 */
@RestController
@RequestMapping("/api/order/cart")
public class CartController {

    @Resource
    CartService cartService;
    @Operation(summary = "添加商品到购物车")
    @GetMapping("/auth/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable("skuId")Long skuId ,
                            @PathVariable("skuNum")Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return Result.ok();
    }

    @GetMapping("/auth/cartList")
    public Result cartList(){
        List<CartItem> cartItemList =  cartService.cartList();
        return Result.ok().data(cartItemList);
    }
    @DeleteMapping("/auth/deleteCart/{skuId}")
    public Result deleteCartItem(@PathVariable("skuId")Long skuId){
        cartService.deleteCartItem(skuId);
        return Result.ok();
    }
    @GetMapping("/auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.ok();
    }
    @GetMapping("/auth/checkCart/{skuId}/{status}")
    public Result checkCart(@PathVariable("skuId")Long skuId,
                            @PathVariable("status") Integer status){
            cartService.checkCart(skuId,status);
            return  Result.ok();
    }
    @GetMapping("/auth/allCheckCart/{status}")
    public Result allCheckCart(@PathVariable("status") Integer status){
            cartService.allCheckCart(status);
            return Result.ok();
    }

    @GetMapping("/auth/checkedCartList")
    public Result checkedCartList(){
        List<CartItem> cartItemList = cartService.checkedCartList();
        return Result.ok().data(cartItemList);
    }

    @DeleteMapping("/auth/deleteCheckedCart")
    public Result deleteCheckedCart(){
        cartService.deleteCheckedCart();
        return Result.ok();
    }




}
